package com.example.demo.web.controller;

import com.example.demo.core.handler.exception.ResultBO;
import com.example.demo.core.handler.exception.ResultTool;
import com.example.demo.sys.service.MessageService;
import com.example.demo.sys.service.bo.MessageBO;
import com.example.demo.web.utils.JwtService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private MessageService messageService;
    @Autowired
    private JwtService jwtService;

    @GetMapping(value="/messages")
    @ResponseBody
    public ResultBO<?> getHomeMessages(HttpServletRequest req) {
        List<MessageBO> msgs = messageService.getHomeMessages(jwtService.getUid(req));
        return ResultTool.success(msgs);
    }
}
